package com.twu.biblioteca;

import java.io.*;
import com.twu.biblioteca.*;
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.lang.*;


public class BibliotecaApp {

    int option;
    String pwd;
    String id;

    AllBooks allbooks = new AllBooks();
    boolean loginStatus;
    AllMovies allmovies = new AllMovies();
    Scanner scan = new Scanner(System.in);

    Book b1 = new Book("Head First Java","Bert Bates","9235","978756410",true);
    Book b2 = new Book("JavaScript the good parts","Anon","9247","923882324",true);
    Book b3 = new Book("Two States", "Chetan Bhagat", "9345","899234523",false);
    UserDetail user = new UserDetail("Saranya","111-1111","hello","saranyak.236@gmail.com",950092561);

    Movie movie1 = new Movie("Kahaani","Sujoy Ghosh",2012,"7");
    Movie movie2 = new Movie("Inception","Christoper Nolan",1970,"8");
    Movie movie3 = new Movie("Shutter Island","Martin Scorsese",2010,"7");
    Movie movie4 = new Movie("Life Of Pie","AngLee",2012,"5");
    Movie movie5 = new Movie("Viswaroopam","Kamal Hasaan",2013,"N/A");


    public static void main(String[] args) {



      BibliotecaApp biblioteca= new BibliotecaApp();

      biblioteca.setup();

      System.out.println(biblioteca.welcomeScreen());

      Scanner scan= new Scanner(System.in);
      System.out.println("Enter user id and passsword:");
      biblioteca.id=scan.next();
      biblioteca.pwd=scan.next();

      biblioteca.loginStatus=biblioteca.user.login(biblioteca.id,biblioteca.pwd);
      if(!biblioteca.loginStatus)
      System.out.println("Enter correct login id and password");

        biblioteca.chooseOption();


   }

    public void setup(){
        allbooks.addBooks(b1) ;
        allbooks.addBooks(b2);
        allbooks.addBooks(b3);
        allmovies.addMovies(movie1);
        allmovies.addMovies(movie2);
        allmovies.addMovies(movie3);
        allmovies.addMovies(movie4);
        allmovies.addMovies(movie5);

    }



    public String welcomeScreen(){

      StringBuilder sb = new StringBuilder();
      sb.append("Welcome to Library!");
      return sb.toString();
  }



   public void chooseOption() {


       String output;
       boolean continuation=true;

       while(continuation)
       {

        System.out.println("Choose an option:\n 1.View all book details\n 2.View a movie detail\n 3.Reserve a book\n 4.Return a book\n 5.View Membership Details");
        option=scan.nextInt();

        switch(option) {

           case 1:
               output=allbooks.displayAll();
               System.out.println(output);
               break;

           case 2:
               Scanner newscan = new Scanner(System.in);

               System.out.println("Enter movie name:");
               String movieName= newscan.nextLine();
               System.out.println("");
               output=allmovies.displayMovieDetails(movieName);

               System.out.println(output);
               break;

           case 3:
               if(loginStatus){
                    System.out.println("Enter Accession Number of the Book:");
                    String accNo=scan.next();
                    output=allbooks.findByAccessionNumber(accNo,1);
                    System.out.println(output);

               }
               else
                   System.out.println("You need to login to reserve a book");
               break;

            case 4:
               if(loginStatus){
                    System.out.println("Enter Accession Number of the Book:");
                    String accNo=scan.next();
                    output=allbooks.findByAccessionNumber(accNo,2);
                    System.out.println(output);

               }
               else
                   System.out.println("You need to login to reserve a book");
               break;

            case 5:
                output=user.getMembershipDetails(id,pwd);
                System.out.println(output);
       }

           System.out.println("You want to continue? true/false:");
           continuation=scan.nextBoolean();

    }
   }

}
     
